<template>
<view class="homeLayout jbbj">
	<const-nav-bar title="推荐"></const-nav-bar>
	<view class="banner">
		<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)"
		indicator-active-color="#fff" autoplay><!-- 自动的轮播图 -->
			<swiper-item v-for="item in bannerList" :key="item._id">
			<navigator v-if="item.target == 'miniProgram'" 
			:url="item.url" 
			class="like"
			target="miniProgram"
			:app-id="item.appid"
			>
			<image :src="item.picurl" mode="aspectFill"></image>
			</navigator>
			<navigator v-else :url="`/pages/classlist/classlist?${item.url}`" class="like">
			<image :src="item.picurl" mode="aspectFill"></image>						
			</navigator>					
			</swiper-item>				
		</swiper>
	</view>

<!-- //公告//	 -->
	<view class="notice">
		<view class="left">
			<uni-icons type="sound-filled" size="20" color="#28b389"></uni-icons>
			<text>公告</text>
		</view>
		<view class="center">
			<swiper vertical autoplay interval="1500" duration="300" circular>
			<swiper-item v-for="item in noticeList":key="item._id">
				<navigator :url="'/pages/notice/detail?id='+item._id">
				{{item.title}}
				</navigator>
				</swiper-item>
			</swiper>
		</view>
		<view class="rigth">
			<uni-icons type="right" size="16" color="#28b389"></uni-icons>
		</view>
	</view>
	
	<view class="select">
		<common-title>
			<template #name>每日推荐</template>
			<template #custom>
				<view class="date">
					<uni-icons type="calendar" size="18" color="#28b389"></uni-icons>
					<view class="text">
						<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
					</view>
				</view>
			</template>
		</common-title>
		<view class="content">
			<scroll-view scroll-x >
				<view class="box" v-for="item in randomList":key="item._id" @click="goback(item._id)">
					<image :src="item.smallPicurl" mode="aspectFill"></image>
				</view>
			</scroll-view>
			
		</view>
	</view>
	
	<view class="theme">
		<common-title>
			<template #name>专题精选</template>
			<template #custom>
				<navigator url="/pages/classify/classify" open-type="reLaunch" class="more">More+</navigator>
			</template>
		</common-title>
		<view class="content">
		<theme-title v-for="item in classifyList " 
		:key="item.id"
		:item="item"
		></theme-title>
		<theme-title :isMore="true"></theme-title>
		</view>
	</view>
</view>
</template>

<script setup>
import { ref } from 'vue';
import {onShareAppMessage,onShareTimeline} from "@dcloudio/uni-app";
import {apiGetBanner,apiGetDayRandom,apiGetNotice,apiGetClassify} from "@/api/apis.js"
const bannerList=ref([]);
const randomList=ref([]);
const noticeList = ref([]);
const classifyList= ref([]);


const getBanner = async ()=>{
	let res =await apiGetBanner();	
	bannerList.value = res.data;	
}

const getDayRandom = async ()=>{
	let res =await apiGetDayRandom();
	randomList.value = res.data	
}

const getNotice = async()=>{
	let res =await apiGetNotice({select:true});
	noticeList.value = res.data
}

const getClassify =async()=>{
	let res =await apiGetClassify({
		select:true
	});
	classifyList.value = res.data
	console.log(res);
}
		
// //轮播图		
// const  getBanner =async ()=>{
// 	let res =await uni.request({
// 		url:"https://tea.qingnian8.com/api/bizhi/homeBanner",
// 		header:{
// 			"access-key":"whh1223@"
// 		}
// 	})
// 	console.log(res.data.errCode==0);

// if(res.data.errCode===0){
// 	bannerList.value=res.data.data
// 	}
// }
// //每日推荐	 
// const getDayRandom = async () =>{
// 	let res =await uni.request({
// 	   url:"https://tea.qingnian8.com/api/bizhi/randomWall",
// 	   header:{
// 		   "access-key":"whh1223@"
// 	   }
//     })
	

// if(res.data.errCode===0){
// 	randomList.value=res.data.data
// 	}	
// }

// //公告内容
// const getNotice = async () =>{
// 	let res =await uni.request({
// 	   url:"https://tea.qingnian8.com/api/bizhi/wallNewsList",
// 	   header:{
// 		   "access-key":"whh1223@"
// 	   },
// 	   // data:{
// 		  //  select:true
// 	   // }
//     })

// if(res.data.errCode===0){
// 	noticeList.value=res.data.data
// 	}
// }


	 
//跳转页面
const  goback=(id)=>{	
	uni.setStorageSync("storgClassList",randomList.value);
	uni.navigateTo({
		url:"/pages/yulai/yulai?id="+id
	})
	
}

//分享给好友
onShareAppMessage((e)=>{
	return {
		title:"好看的手机壁纸",
		path:"/pages/classify/classify"
	}
})

//分享朋友圈
onShareTimeline(()=>{
	return {
		title:"星R壁纸" //必须要上线的小程序才能出现
	}
})

getBanner();
getDayRandom();
getNotice();
getClassify();
</script>

<style lang="scss" scoped>
 

</style>
